//
//  ProductInfocell.swift
//  Wmsmobile
//
//  Created by Nick xu on 16/8/5.
//  Copyright © 2016年 hddden. All rights reserved.
//

import UIKit
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l < r
  case (nil, _?):
    return true
  default:
    return false
  }
}

fileprivate func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l > r
  default:
    return rhs < lhs
  }
}


class HDDoubleProductInfocell: HDFounctionBaseCell , HDgetAndSetProtocol {
    //MARK: - property
    override var info: [String : String]?{
        didSet{
            self.textField.text = info!["text"]
        }
    }
    lazy var textField: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.hexStringToUIColor("#666666")
        label.font = UIFont.systemFont(ofSize: self.getFont())
//        label.backgroundColor = UIColor.redColor()
        return label
    }()
    lazy var textFieldRight:UILabel = {
        let label = UILabel()
        label.textColor = UIColor.hexStringToUIColor("#666666")
        label.font = UIFont.systemFont(ofSize: self.getFont())
        return label
    }()
    lazy var titleViewRight:UILabel = {
        let titleView = UILabel()
        if titleView.text?.characters.count > 5{
            titleView.font = UIFont.boldSystemFont(ofSize: 12)
        }
        titleView.font = UIFont.systemFont(ofSize: self.getFont())
        titleView.textColor = UIColor.hexStringToUIColor("#333333")
        titleView.adjustsFontSizeToFitWidth = true
        //        titleView.backgroundColor = UIColor.redColor()
        return titleView
    }()
    lazy fileprivate var sepView:UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.hexStringToUIColor("#cccccc")
        return view
    }()

    //MARK: - life cycle
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: UITableViewCellStyle.default, reuseIdentifier: "ProductInfocell")
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.setUpUI()
    }
    
    required init() {
        super.init(style: UITableViewCellStyle.default, reuseIdentifier: "ProductInfocell")
        self.setUpUI()
    }
    //MARK: - public
    override func clearContent() {
        self.textField.text = ""
        self.textFieldRight.text = ""
    }
    //MARK: - delegate
    func getText() -> (String?) {
        return "\(textField.text ?? "")/\(textFieldRight.text ?? "")"
    }
    func SetText(_ text: String?) {
        let textArr = text?.components(separatedBy: "/")
        textField.text = textArr?.first
        textFieldRight.text = textArr?.count > 1 ? textArr?.last : ""
    }
    //MARK: - private
    func setUpUI(){
//        self.textLabel?.adjustsFontSizeToFitWidth = true
        self.addSubview(self.textField)
        self.addSubview(self.titleViewRight)
        self.addSubview(self.textFieldRight)
        self.addSubview(self.sepView)
        textField.snp.makeConstraints { (make) in
            make.leading.equalTo(self).offset(inputViewToCellSpace-10)
            make.top.equalTo(self).offset(FTCellTopSpace+4)
            make.bottom.equalTo(self).offset(-FTCellTopSpace-5)
            make.trailing.equalTo(self).offset(-FTCellHorizontalSpace)
        }
        textFieldRight.snp.makeConstraints { (make) in
            make.leading.equalTo(self.snp.centerX).offset(inputViewToCellSpace - 10)
            make.centerY.equalTo(self.contentView)
            
        }
        titleViewRight.snp.makeConstraints { (make) in
            make.leading.equalTo(self.snp.centerX).offset(15)
            make.centerY.equalTo(self.contentView)
        }
        self.sepView.snp.makeConstraints { (make) in
            make.top.equalTo(self.contentView).offset(7)
            make.bottom.equalTo(self.contentView).offset(-7)
            make.centerX.equalTo(self.contentView)
            make.width.equalTo(1)
        }
    }
    
}
